package es.ucm.fdi.isbc.viviendas.gui;

import java.awt.BorderLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;

import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

import es.ucm.fdi.isbc.viviendas.representacion.DescripcionVivienda;
import es.ucm.fdi.isbc.viviendas.representacion.ExtrasFinca;

@SuppressWarnings("serial")
public class PanelExtrasFinca extends JPanel{

	private JCheckBox box_ascensor;
	private JCheckBox box_trastero;
	private JCheckBox box_energiaSolar;
	private JCheckBox box_servPorteria;
	private JCheckBox box_parkingComunitario;
	private JCheckBox box_garajePrivado;
	private JCheckBox box_videoportero;
	
	public PanelExtrasFinca(){
		
		setLayout(new GridBagLayout());
		GridBagConstraints c=new GridBagConstraints();
		c.gridx=0;/*posicion x de la tabla*/
		c.gridy=0;/*posicion y de la tabla*/
		c.gridwidth = 1; /*anchura en celdas*/
		c.gridheight = 1;/*altura en celdas*/
		
		c.insets=new Insets(3,3,3,3);
		
		/*creo los labels que mostrare en la pantalla del JDialog*/
		JLabel label_ascensor=new JLabel("Ascensor");
		JLabel label_trastero=new JLabel("Trastero");
		JLabel label_energiaSolar=new JLabel("Energia Solar");
		JLabel label_servPorteria=new JLabel("Servicio Porteria");
		JLabel label_parkingComunitario=new JLabel("Parking Comunitario");
		JLabel label_garajePrivado=new JLabel("Garage Privado");
		JLabel label_videoportero=new JLabel("VideoPortero");
		
		/*colocamos los labels en las posiciones correspondientes de la ventana*/
		c.anchor=GridBagConstraints.EAST;
		c.gridy=0;
		this.add(label_ascensor, c);
		c.gridy=1;
		this.add(label_trastero, c);
		c.gridy=2;
		this.add(label_energiaSolar, c);
		c.gridy=3;
		this.add(label_servPorteria, c);
		c.gridx=2;
		c.gridy=0;
		this.add(label_parkingComunitario, c);
		c.gridy=1;
		this.add(label_garajePrivado, c);
		c.gridy=2;
		this.add(label_videoportero, c);
		
		c.gridy=0;
		c.gridx=1;
		
		/*inicializamos los checkboxes*/
		
		box_ascensor=new JCheckBox();
		box_trastero=new JCheckBox();
		box_energiaSolar=new JCheckBox();
		box_servPorteria=new JCheckBox();
		box_parkingComunitario=new JCheckBox();
		box_garajePrivado=new JCheckBox();
		box_videoportero=new JCheckBox();
		
		/*colocamos los checkboxes en la ventana*/
		c.gridx=1;
		c.gridy=0;
		this.add(box_ascensor, c);
		c.gridy=1;
		this.add(box_trastero, c);
		c.gridy=2;
		this.add(box_energiaSolar, c);
		c.gridy=3;
		this.add(box_servPorteria, c);
		c.gridx=3;
		c.gridy=0;
		this.add(box_parkingComunitario, c);
		c.gridy=1;
		this.add(box_garajePrivado, c);
		c.gridy=2;
		this.add(box_videoportero, c);

	}
	
	public void rellenarQuery(DescripcionVivienda q){
		ExtrasFinca ef = new ExtrasFinca(1);
		if(box_ascensor.isSelected())
			ef.setAscensor(box_ascensor.isSelected());
		if(box_trastero.isSelected())
			ef.setTrastero(box_trastero.isSelected());
		if(box_energiaSolar.isSelected())
			ef.setEnergiaSolar(box_energiaSolar.isSelected());
		if(box_servPorteria.isSelected())
			ef.setServPorteria(box_servPorteria.isSelected());
		if(box_parkingComunitario.isSelected())
			ef.setParkingComunitario(box_parkingComunitario.isSelected());
		if(box_garajePrivado.isSelected())
			ef.setGarajePrivado(box_garajePrivado.isSelected());
		if(box_videoportero.isSelected())
			ef.setVideoportero(box_videoportero.isSelected());
		q.setExtrasFinca(ef);
		}
	
	public void reset(){
		box_ascensor.setSelected(false);
		box_trastero.setSelected(false);
		box_energiaSolar.setSelected(false);
		box_servPorteria.setSelected(false);
		box_parkingComunitario.setSelected(false);
		box_garajePrivado.setSelected(false);
		box_videoportero.setSelected(false);
	}
	
	public static void main(String[] args) {
		JFrame frame = new JFrame("Panel Filtro");
        frame.setLayout(new BorderLayout());
        frame.setResizable(false);
        //frame.setSize(800, 700);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        //frame.setLocationRelativeTo(null);
   
        
        //Add content to the window.
        frame.add(new PanelExtrasFinca(),BorderLayout.CENTER);
      

        //Display the window.
        frame.pack();
        frame.setVisible(true);

	}

}

